package com.niuzi.servlet;

import com.niuzi.entity.Teacher;
import com.niuzi.util.DataUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Administrator
 * 添加教师
 */
@WebServlet(urlPatterns = "/addteacher")
public class AddTeacherServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String thname = req.getParameter("thname");
        String sex = req.getParameter("sex");
        String age = req.getParameter("age");
        String bookname = req.getParameter("bookname");

        System.out.println("姓名："+thname+",性别："+sex+",年龄："+age+",教课名："+bookname);

        Teacher teacher = new Teacher() ;
        teacher.setThname(thname);
        teacher.setSex(sex);
        teacher.setAge(age);
        teacher.setBookname(bookname);

        DataUtil.addTeacher(teacher);
        resp.sendRedirect("addteacher.jsp?pd=1");

    }
}
